package m.app.action;

import m.base.util.PowerUtil;
import m.common.action.ActionMeta;
import m.common.model.type.FieldType;
import m.common.model.util.ModelQueryList;
import m.common.model.util.QueryCondition;
import m.common.model.util.QueryOrder;
import m.store.model.*;
import m.store.service.StoreNumberService;
import m.system.document.DocumentMeta;
import m.system.document.DocumentMethodMeta;
import m.system.document.DocumentParamMeta;
import m.system.exception.MException;
import m.system.util.JSONMessage;
import m.system.util.StringUtil;

import java.util.ArrayList;
import java.util.Date;

@ActionMeta(name = "app/guestBackAmount",title="app货款往来")
public class GuestBackAmountAction extends AppAction{
    private GuestBackAmount model;
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "资金往来登记列表",permission = true),
        params = {
            @DocumentParamMeta(name = "page.index",description = "分页开始位置",type = FieldType.INT),
            @DocumentParamMeta(name = "page.num",description = "分页每页数量",type = FieldType.INT),
            @DocumentParamMeta(name = "params[type]",description = "类型",type = FieldType.STRING,length = 50),
            @DocumentParamMeta(name = "params[oid@eq]",description = "条件示例，字段和操作符中间用@，值为空不添加",type = FieldType.STRING,length = 50),
            @DocumentParamMeta(name = "params[oid#desc]",description = "排序示例，字段和操作符中间用#，值为空不生效",type = FieldType.STRING,length = 50)
        }
    )
    public JSONMessage myList() throws Exception {
        ModelQueryList queryList=toQueryList(GuestBackAmount.class,"*","guest.*");
        queryList.addCondition(QueryCondition.eq("type",getParamsValue("type")));
        queryList.addCondition(QueryCondition.eq("store.oid", PowerUtil.getSessionStoreOid()));
        return JSONMessage.success("查询成功").push("page",ModelQueryList.getModelPageInfo(queryList));
    }
    @DocumentMeta(
        method = @DocumentMethodMeta(title = "获取资金往来信息",permission = true),
        params = {
            @DocumentParamMeta(name = "model.oid",description = "主键",type = FieldType.STRING,length = 50,notnull = true)
        }
    )
    public JSONMessage getInfo() throws Exception {
        if(null!=model&&!StringUtil.isSpace(model.getOid())){
            model= ModelQueryList.getModel(model,"*","guest.name");
        }else if(null!=model&&!StringUtil.isSpace(model.getType())){
            model.setBackDate(new Date());
            model.setLinkStatus(GuestBackAmount.LinkStatus_No);
            model.setBusiness(GuestBackAmount.Business_Yes);
        }else{
            throw new MException(this.getClass(),"参数错误");
        }
        return JSONMessage.success("查询成功")
                .push("model",model);
    }

    public GuestBackAmount getModel() {
        return model;
    }

    public void setModel(GuestBackAmount model) {
        this.model = model;
    }
}
